<template>
  <div>
    <h1>订单管理</h1>

    <!-- 搜索 -->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="">
        <el-cascader :options="options" clearable @change="orderChange" />
      </el-form-item>
      <el-form-item label="">
        <el-input
          v-model="add"
          class="input"
          placeholder="请输入内容"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <template slot-scope="scope">
          <el-button type="success" @click="orderScreen(scope.row)"
            >查询</el-button
          >
        </template>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <el-table :data="List" stripe style="width: 100%" border>
      <el-table-column prop="orderNo" label="订单号" width="180">
      </el-table-column>
      <el-table-column prop="receiverName" label="收件人" width="180">
      </el-table-column>
      <el-table-column prop="status" label="订单状态"> </el-table-column>
      <el-table-column prop="payment" label="订单总价"> </el-table-column>
      <el-table-column prop="createTime" label="创建时间"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click="edd_order(scope.row.orderNo)"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页器 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      @current-change="change"
    >
    </el-pagination>
  </div>
</template>

<script>
import { ORDER, orderSearch } from "../request/http";
export default {
  data() {
    return {
      List: [],
      size: 10,
      page: 1,
      total: 0,
      add: "",
      options: [
        {
          value: "id",
          label: "按订单号查询",
        },
      ],
    };
  },
  mounted() {
    this.orderList();
  },
  methods: {
    async orderList() {
      const { data: res } = await ORDER(`/order/list.do`, {
        pageSize: this.size,
        pageNum: this.page,
      });
      console.log(res);
      this.List = res.data.list;
      this.total = res.data.total;
    },
    //分页器
    change(val) {
      this.page = val;
      this.orderList();
    },

    // change事件
    orderChange(val) {
      this.mag = val;
      console.log(val);
    },
    //搜索按钮
    orderScreen() {
      console.log(this.add);
      if (this.add !== "") {
        orderSearch(`/order/search.do`, {
          orderNo: this.add,
          pageNum: this.page,
        }).then((res) => {
          console.log(res);
          this.List = res.data.data.list;
          this.total = res.data.data.total;
        });
      }
    },

    //查看单行的id
    edd_order(id) {
      console.log(id);
      this.add = id;
      this.$router.push({name:'edit_deatil',params:{id}}); //跳转订单详情页
    },
  },
};
</script>